<?php
class Framework{
	public static function Run(){
		//echo "ok";
		self::init();
		self::autoload();
		self::dispanch();
	}
	
	private static  function init(){
		define('DS', DIRECTORY_SEPARATOR);
		define('ROOT_PATH', getcwd().DS);
		define('APP_PATH', ROOT_PATH.'application'.DS);
		define('FRAMEWORK_PATH', ROOT_PATH.'framework'.DS);
		define('VIEWS_PATH', ROOT_PATH.'views'.DS);
		define('CORE_PATH', FRAMEWORK_PATH.'core'.DS);
		define('DB_PATH', FRAMEWORK_PATH.'databases'.DS);
		define('LIB_PATH', FRAMEWORK_PATH.'libraries'.DS);
		define('CONFIG_PATH', APP_PATH.'config'.DS);
		define('MODEL_PATH', APP_PATH.'models'.DS);
		define('CONTROLLOR_PATH', APP_PATH.'controllers'.DS);
		define('HELPER_PATH', FRAMEWORK_PATH.'helpers'.DS);
		
		//获取参数
		//define(PLATFORM, isset($_GET['p'])?$_GET['p']:"Index");
		define('CONTROLLER',isset($_GET['c'])?$_GET['c']:"Index");
		define('ACTION',isset($_GET['a'])?$_GET['a']:"Index");
		
		
		//载入核心类文件
		require_once CORE_PATH.'Controller.class.php';
		require_once CORE_PATH.'Model.class.php';
		require_once DB_PATH.'Mysql.class.php';
		//require_once CONTROLLOR_PATH.'BaseController.class.php';
		
		session_start();
		
		//载入配置文件
		$GLOBALS['config']=require_once CONFIG_PATH."config.php";
	
	}
	
	//自动载入
	private static function autoload(){
		
		spl_autoload_register('self::load');
		
	}
	
	//路由分发
	private static function dispanch(){
		
		$controllertname=CONTROLLER."Controller";
		$actionname=ACTION."Action";
		$controller=new $controllertname();
		$controller->$actionname();
		
	}
	private static  function load($classname){
		
		if (substr($classname, -10)=="Controller") {
			require_once CONTROLLOR_PATH."{$classname}.class.php";
		}elseif (substr($classname, -5)=="Model"){
			require_once MODEL_PATH."{$classname}.class.php";
		}
	}
	
	
	
}